Telegram Group & Telegram Channel
📊 Своя метрика в Prometheus

Хотите отслеживать, сколько запросов прилетает в ваше приложение? Или сколько задач выполнилось? Делается это за 5 шагов — через кастомные метрики.

Попробуем реализовать пример: считаем количество HTTP-запросов в приложении на Go.

1. Подключаем библиотеку Prometheus:
go get github.com/prometheus/client_golang/prometheus


2. Создаём счётчик:
var requestCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "myapp_http_requests_total",
Help: "Total number of HTTP requests",
})


3. Регистрируем метрику:
func init() {
prometheus.MustRegister(requestCounter)
}


requestCounter будет инкрементироваться при запросе приложения.

4. Добавляем endpoint для Prometheus:
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))


5. Пишем конфиг на стороне Prometheus
scrape_configs:
- job_name: 'myapp'
metrics_path: /metrics
static_configs:
- targets: ['localhost:8080']


📍 Всё — теперь http://localhost:8080/metrics отдаёт данные, которые можно добавить в дашборд в Prometheus.

🐸Библиотека devops'a #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/devopsslib/3737
Create:
Last Update:

📊 Своя метрика в Prometheus

Хотите отслеживать, сколько запросов прилетает в ваше приложение? Или сколько задач выполнилось? Делается это за 5 шагов — через кастомные метрики.

Попробуем реализовать пример: считаем количество HTTP-запросов в приложении на Go.

1. Подключаем библиотеку Prometheus:

go get github.com/prometheus/client_golang/prometheus


2. Создаём счётчик:
var requestCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "myapp_http_requests_total",
Help: "Total number of HTTP requests",
})


3. Регистрируем метрику:
func init() {
prometheus.MustRegister(requestCounter)
}


requestCounter будет инкрементироваться при запросе приложения.

4. Добавляем endpoint для Prometheus:
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))


5. Пишем конфиг на стороне Prometheus
scrape_configs:
- job_name: 'myapp'
metrics_path: /metrics
static_configs:
- targets: ['localhost:8080']


📍 Всё — теперь http://localhost:8080/metrics отдаёт данные, которые можно добавить в дашборд в Prometheus.

🐸Библиотека devops'a #буст

BY Библиотека девопса | DevOps, SRE, Sysadmin




Share with your friend now:
tg-me.com/devopsslib/3737

View MORE
Open in Telegram


Библиотека девопса | DevOps SRE Sysadmin Telegram | DID YOU KNOW?

Date: |

How Does Bitcoin Mining Work?

Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

Библиотека девопса | DevOps SRE Sysadmin from tw


Telegram Библиотека девопса | DevOps, SRE, Sysadmin
FROM USA